package org.digitaldomination.thefinalcountdown;

import java.util.concurrent.TimeUnit;

import android.content.Context;

public class Globals {
	Context myContext;
	Globals(Context c)
	{
		myContext = c;
	}
	public String writetime(long countdown)
	{
		long secondsto;
		long now = System.currentTimeMillis();
		now = TimeUnit.MILLISECONDS.toSeconds(now);
		if(countdown > now)
		{
			secondsto = countdown - now;
		}
		else
		{
			secondsto = now - countdown;
		}
		long days = secondsto / 86400;
		long hours = (secondsto / (60 * 60)) % 24;
		long minutes = (secondsto / 60) % 60;
		long seconds = (secondsto % 60);
		return String.format("%d dager, %d timer, %d minutter, og %d sekunder", days, hours, minutes, seconds);
	}
	public String writeprogress(long countdown, long count_to)
	{
		long secondsto;
		float calc;
		long now = System.currentTimeMillis();
		now = TimeUnit.MILLISECONDS.toSeconds(now);
		if(count_to < now)
		{
			secondsto = 100;
		}
		else
		{
			long totaltime = count_to - countdown;
			calc = now - countdown;
			if(totaltime == 0)
			{
				secondsto = 100;
			}
			else
			{
				secondsto = (long) Math.floor(calc / totaltime * 100);
			}
		}
		return String.format("%d percent", secondsto);
	}
}
